﻿mini.parse();
var form = new mini.Form("form1");
var action;
function SaveData() {
    var o = form.getData();
    var json = mini.encode([o]);
    form.validate();
    if (form.isValid() == false) return;
    if (action == "edit") {
        $.ajax({
            url: "../Service/SystemManageHandler.ashx?action=ModifyUser",
            data: { data: json },
            type: 'POST',
            success: function(text) {
                CloseWindow("save");
            },
            error: function(jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
            }
        });
    }
}
function SetData(data) {
    if (data.action == "edit") {
        var UserName = mini.getbyName("UserName");
        UserName.setEnabled(false);
        data = mini.clone(data);
        action = data.action;
        $.ajax({
            url: "../service/SystemManageHandler.ashx?action=GetUserInfo&UserId=" + data.UserId,
            cache: false,
            success: function(text) {
                var o = mini.decode(text);
                form.setData(o);
                form.setChanged(false);
            }
        });
    }
}

function CloseWindow(action) {
    if (action == "close" && form.isChanged()) {
        if (confirm("数据被修改了，是否先保存？")) {
            return false;
        }
    }
    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
    else window.close();
}

function onOk(e) {
    SaveData();
}
function onCancel(e) {
    CloseWindow("cancel");
}